package com.aiks.single.singlemavenproject.controller;

import com.aiks.single.singlemavenproject.common.CommonResult;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 心跳.
 *
 * @author <a href="mailto:yuanz@yxt.com">yuanz</a>
 * @date 2021-08-26 09:56
 * @since 1.0.0
 **/
@RestController
@RequestMapping("")
public class ServerStatusController {
    @Value("${application.version:default}")
    private String version;
    @Value("${application.build:default}")
    private String build;
    @Value("${application.version2:default}")
    private String version2;
    @Value("${spring.profiles.active}")
    private String active;
    
    @Autowired
    private Environment environment;
    
    /**
     * 心跳.
     *
     * @return CommonResult<HashMap < String, Object>>
     */
    @GetMapping("/serverStatus")
    public CommonResult<HashMap<String, Object>> serverStauts() {
        Map<String, Object> map = Maps.newHashMapWithExpectedSize(3);
        map.put("version", version);
        map.put("version2", version2);
        map.put("active", active);
        map.put("build", build);
        map.put("status", "up");
        map.put("environment", environment.toString());
        return CommonResult.ok(map);
    }
    
}
